package xyz.lwm.lazycat.utility.scan;

import java.util.List;
import java.util.function.Predicate;

/**
 * Scanner
 *
 * @param <S> source
 * @param <T> target
 */
public interface Scanner<S, T> {

    // file:/usr/local/**/test**.txt
    // file:D:/tmp/test.txt
    String FILE_PREFIX = "file:";

    // classpath:/com/**/mapper/test/**.txt
    String CLASSPATH_PREFIX = "classpath:";

    // all characters
    char WILDCARD = '*';

    // one character
    char CHAR = '?';

    // slash, separator of path
    char SLASH = '/';

    // dot, file suffix or package separator
    char DOT = '.';

    // regex start
    char START = '^';

    // regex end
    char END = '$';

    // protocol of url, file
    String FILE_PROTOCOL = "file";

    // protocol of url, jar
    String JAR_PROTOCOL = "jar";

    // class suffix
    String CLASS_SUFFIX = ".class";

    // class path environment name
    String CLASS_PATH_ENV_NAME = "java.class.path";

    // user directory environment name
    String USER_DIR_ENV_NAME = "user.dir";

    /**
     * 扫描源并获取结果
     *
     * @param source 源
     * @return 结果集
     */
    default List<T> scan(S source) {
        return scan(source, t -> true);
    }

    /**
     * 扫描源并获取结果
     *
     * @param source 源
     * @param filter 结果过滤器
     * @return 结果集
     */
    List<T> scan(S source, Predicate<T> filter);

}
